// LemCoop
// Copyright (C) 2013  Oliver Naumann <bldrax@gmail.com>

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

#include "teststate.h"

TestState::TestState(GameEngine* engine) : GameState(engine)
{
}

void TestState::Init()
{
	m_test_dialog = new Dialog();

	ALLEGRO_FONT* font2 = al_load_font("media/fonts/candara.ttf", 12, NULL);
	ValueList* vlist = new ValueList("lis1", 500, 420, 300, 256, font2, 25);
	m_test_dialog->AddElement(vlist);

	vlist->AddEntry("Eintrag 1", "1");
	vlist->AddEntry("Eintrag 2", "2");
	vlist->AddEntry("Eintrag 3", "3");
	vlist->AddEntry("Eintrag 4", "4");
	vlist->AddEntry("Eintrag 5", "5");
	vlist->AddEntry("Eintrag 6", "6");
	vlist->AddEntry("Eintrag 7", "7");
	vlist->AddEntry("Eintrag 8", "8");
	vlist->AddEntry("Eintrag 9", "9");
	vlist->AddEntry("Eintrag 10", "10");
	vlist->AddEntry("Eintrag 11", "11");
	vlist->AddEntry("Eintrag 12", "12");

	ALLEGRO_FONT* font = al_load_font("media/fonts/candara.ttf", 20, NULL);
	Button* button = new Button("but1", 10, 10, 500, 80, std::bind([this]() {}));
	m_test_dialog->AddElement(button);

}

void TestState::HandleInput(ALLEGRO_EVENT next_event)
{
	switch (next_event.type)
	{
	case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN:
		m_test_dialog->PrimaryMouseButtonDown(next_event.mouse.x, next_event.mouse.y);
		break;

	case ALLEGRO_EVENT_MOUSE_BUTTON_UP:
		m_test_dialog->PrimaryMouseButtonUp(next_event.mouse.x, next_event.mouse.y);
		break;

	case ALLEGRO_EVENT_MOUSE_AXES:
		m_test_dialog->MouseAxisChange(next_event.mouse.x, next_event.mouse.y);
	}
}

void TestState::Update(float timing_factor)
{
	m_test_dialog->Update();
}

void TestState::Draw()
{
	m_test_dialog->Draw();
}